package com.atguigu.lease.common.context;

public class LoginUserContext {
    //线程本地变量，将登陆用户对象存储于该对象
    public static ThreadLocal<LoginUser> loginUser = new ThreadLocal<>();

 //存储用户登录信息：用户id和用户名
    public static void setLoginUser(Long userId, String username) {
        LoginUser user = new LoginUser();
        user.setUserId(userId);
        user.setUsername(username);
        loginUser.set(user);
    }

//获取用户的登录信息
    public static LoginUser getLoginUser() {
        return loginUser.get();
    }

 //注销时清除用户的登录信息
    public static void clear() {
        loginUser.remove();
    }

}
